package org.example.service;

import com.mysql.cj.Session;
import org.example.dao.BookDao;
import org.example.javabean.Book;
import org.example.javabean.Collection;
import org.example.javabean.History;
import org.example.javabean.User;


import javax.servlet.http.HttpSession;
import java.util.List;

public class BookService {
    private BookDao bookDao = new BookDao();

    public List<Book> searchAllBooks(int pageNum, int pageSize) {

        List<Book> books = bookDao.selectAll(pageNum, pageSize);

        return books;
    }


    public List<History> searchHistoryBooks(int pageNum, int pageSize, HttpSession session) {

        List<History> historys = bookDao.selectHistory(pageNum, pageSize, (String) session.getAttribute("username"));

        return historys;
    }

    public int countNum() {

        return bookDao.selectAllCount();
    }


    public int countHistoryNum(HttpSession session) {

        return bookDao.selectHistoryCount(session.getAttribute("username").toString());
    }


    public int insertBorrowBook(HttpSession session,String book_id) {

        return bookDao.insertBorrowBook(session.getAttribute("username").toString(),book_id);
    }


    public int updateBorrowedStatus(String book_id)
    {
        return bookDao.updateBorrowedStatus(book_id);
    }

    public int deleteHistory(HttpSession session,String book_id)
    {
        return bookDao.deleteHistory(session.getAttribute("username").toString(),book_id);
    }

    public int returnBook(HttpSession session,String book_id)
    {
        return bookDao.returnBook(session.getAttribute("username").toString(),book_id);
    }

    public int updateReturnStatus(String book_id)
    {
        return bookDao.updateReturnStatus(book_id);
    }


    public List<Collection> searchAllCollection(HttpSession session,int pageNum, int pageSize) {

        List<Collection> collections = bookDao.selectAllCollection(session.getAttribute("username").toString(),pageNum,pageSize);

        return collections;
    }


    public int insertCollectionBook(HttpSession session,String book_id) {

        return bookDao.insertCollectionBook(session.getAttribute("username").toString(),book_id);
    }


    public int selectCollectionCount(HttpSession session)
    {
        return  bookDao.selectCollectionCount(session.getAttribute("username").toString());
    }


    public int cancelCollection(HttpSession session,String book_id)
    {
        return bookDao.cancelCollection(session.getAttribute("username").toString(),book_id);
    }
}
